package com.lrkj.payfee.controller;

import com.lrkj.common.utils.DateUtils;
import com.lrkj.common.utils.SecurityUtils;
import com.lrkj.common.utils.StringUtils;
import com.lrkj.payfee.vo.RoomBalanceListVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.payfee.domain.RoomBalance;
import com.lrkj.payfee.service.IRoomBalanceService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 账户余额Controller
 *
 * @author yajun_ren
 * @date 2022-07-25
 */
@RestController
@RequestMapping("/payfee/roomBalance")
@Api(tags = "账户余额")
public class RoomBalanceController extends BaseController
{
    @Autowired
    private IRoomBalanceService roomBalanceService;

    /**
     * 查询账户余额列表
     */
    @ApiOperation(value = "查询账户余额列表", notes = "查询账户余额列表")
    @PreAuthorize("@ss.hasPermi('payfee:roomBalance:list')")
    @GetMapping("/list")
    public TableDataInfo list(RoomBalance roomBalance)
    {
        startPage();
        this.changeParameter(roomBalance.getParams());
        List<RoomBalance> list = roomBalanceService.selectRoomBalanceList(roomBalance);
        return getDataTable(list);
    }

    @ApiOperation(value = "账户余额列表", notes = "账户余额列表")
    @PreAuthorize("@ss.hasPermi('payfee:roomBalance:selectList')")
    @GetMapping("/listBy")
    public TableDataInfo listByNodeId(RoomBalanceListVo roomBalance)
    {
        if(!StringUtils.isEmpty(roomBalance.getTime()) && roomBalance.getTime().equals("no")){
            roomBalance.setTime(DateUtils.dateTimeNow("yyyy-MM-dd"));
        }
       startPage();
        List<RoomBalanceListVo> list = roomBalanceService.selectRoomBalanceByNodeList(roomBalance);
        return getDataTable(list);
    }

    /**
     * 导出账户余额列表
     */
	@ApiOperation(value = "导出账户余额列表", notes = "导出账户余额列表")
    @PreAuthorize("@ss.hasPermi('payfee:roomBalance:export')")
    @Log(title = "账户余额", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RoomBalance roomBalance)
    {
        List<RoomBalance> list = roomBalanceService.selectRoomBalanceList(roomBalance);
        ExcelUtil<RoomBalance> util = new ExcelUtil<RoomBalance>(RoomBalance.class);
        return util.exportExcel(list, "账户余额数据");
    }

    /**
     * 获取账户余额详细信息
     */
	@ApiOperation(value = "获取账户余额详细信息", notes = "获取账户余额详细信息")
    @PreAuthorize("@ss.hasPermi('payfee:roomBalance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(roomBalanceService.selectRoomBalanceById(id));
    }

    /**
     * 新增账户余额
     */
    @ApiOperation(value = "新增账户余额", notes = "新增账户余额")
    @PreAuthorize("@ss.hasPermi('payfee:roomBalance:add')")
    @Log(title = "账户余额", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RoomBalance roomBalance)
    {
        roomBalance.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(roomBalanceService.insertRoomBalance(roomBalance));
    }

    /**
     * 修改账户余额
     */
    @ApiOperation(value = "修改账户余额", notes = "修改账户余额")
    @PreAuthorize("@ss.hasPermi('payfee:roomBalance:edit')")
    @Log(title = "账户余额", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RoomBalance roomBalance)
    {
        return toAjax(roomBalanceService.updateRoomBalance(roomBalance));
    }

    /**
     * 删除账户余额
     */
    @ApiOperation(value = "删除账户余额", notes = "删除账户余额")
    @PreAuthorize("@ss.hasPermi('payfee:roomBalance:remove')")
    @Log(title = "账户余额", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(roomBalanceService.deleteRoomBalanceByIds(ids));
    }
}
